-
Notifications
You must be signed in to change notification settings - Fork 555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add migrate_cri #1519
add migrate_cri #1519
Conversation
a7d36ce
to
01ca3d1
Compare
Could you please provide documentation or description of the newly added features? Such as the purpose of the command, examples of command usage.The documentation can be referenced to commands docs |
01ca3d1
to
89a941e
Compare
ok, i will add it soon,thanks |
89a941e
to
ea40b6f
Compare
pkg/pipelines/migrate_container.go
Outdated
loaderType = common.AllInOne | ||
} | ||
|
||
fmt.Println("MigrateCriPipeline called") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why print the information in this place?
pkg/container/module.go
Outdated
if p.KubeConf.Arg.Type == common.Docker && p.KubeConf.Arg.Role == common.Worker { | ||
p.Tasks = MigrateToDocker(p) | ||
} else if p.KubeConf.Arg.Type == common.Docker && p.KubeConf.Arg.Role == common.Master { | ||
p.Tasks = MigrateMToDocker(p) | ||
} else if p.KubeConf.Arg.Type == common.Conatinerd && p.KubeConf.Arg.Role == common.Worker { | ||
p.Tasks = MigrateToContainerd(p) | ||
} else if p.KubeConf.Arg.Type == common.Conatinerd && p.KubeConf.Arg.Role == common.Master { | ||
p.Tasks = MigrateMToContainerd(p) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommended use:
if p.KubeConf.Arg.Type == common.Docker {
if p.KubeConf.Arg.Role == common.Worker {
// xxx
}
if p.KubeConf.Arg.Role == common.Master {
// xxx
}
}
if p.KubeConf.Arg.Type == common.Conatinerd {
if p.KubeConf.Arg.Role == common.Worker {
// xxx
}
if p.KubeConf.Arg.Role == common.Master {
// xxx
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is better, I will optimize it, thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contributions! There are some comments, PTAL.
cmd/ctl/cri/cri.go
Outdated
@@ -0,0 +1,46 @@ | |||
/* | |||
Copyright 2020 The KubeSphere Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2020 -> 2022
cmd/ctl/cri/migrate_cri.go
Outdated
cmd.Flags().StringVarP(&o.Role, "role", "", "worker", "Role to migrate") | ||
cmd.Flags().StringVarP(&o.Type, "type", "", "docker", "Type to migrate") | ||
cmd.Flags().StringVarP(&o.ClusterCfgFile, "filename", "f", "", "Path to a configuration file") | ||
cmd.Flags().StringVarP(&o.Kubernetes, "with-kubernetes", "", "", "Specify a supported version of kubernetes") | ||
cmd.Flags().StringVarP(&o.DownloadCmd, "download-cmd", "", "curl -L -o %s %s", | ||
`The user defined command to download the necessary binary files. The first param '%s' is output path, the second param '%s', is the URL`) | ||
cmd.Flags().StringVarP(&o.Artifact, "artifact", "a", "", "Path to a KubeKey artifact") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest using Complete() and Validate() methods to check the user input.
pkg/binaries/kubernetes.go
Outdated
@@ -145,3 +146,76 @@ func KubernetesArtifactBinariesDownload(manifest *common.ArtifactManifest, path, | |||
|
|||
return nil | |||
} | |||
|
|||
// CriDownloadHTTP defines the kubernetes' binaries that need to be downloaded in advance and downloads them. | |||
func DockerDownloadHTTP(kubeConf *common.KubeConf, path, arch string, pipelineCache *cache.Cache) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think DockerDownloadHTTP() and ContainerdDownloadHTTP() can be modified as one function, which is can receive variable files.KubeBinary{}
.
For example:
func DownloadBinaries(kubeConf *common.KubeConf, pipelineCache *cache.Cache, binaries ...*files.KubeBinary) {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right,I will optimize it,soon
pkg/container/containerd.go
Outdated
} | ||
|
||
func (d *MigrateSelfNodeTocontainerd) Execute(runtime connector.Runtime) error { | ||
nodeName, _ := runtime.GetRunner().SudoCmd("hostname", true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened if the command hostname
reported an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will optimize it,soon
pkg/binaries/tasks.go
Outdated
func (d *DockerDownload) Execute(runtime connector.Runtime) error { | ||
cfg := d.KubeConf.Cluster | ||
|
||
// var kubeVersion string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove useless codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will optimize it,soon
pkg/pipelines/migrate_container.go
Outdated
loaderType = common.AllInOne | ||
} | ||
|
||
fmt.Println("MigrateCriPipeline called") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will optimize it,soon
} | ||
|
||
if err := MigrateCriPipeline(runtime); err != nil { | ||
fmt.Println(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will optimize it,soon
fmt.Println("MigrateCriPipeline called") | ||
runtime, err := common.NewKubeRuntime(loaderType, args) | ||
if err != nil { | ||
fmt.Println(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line, which will cause print error message twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,I will optimize it,soon
pkg/container/containerd.go
Outdated
nodeName, _ := runtime.GetRunner().SudoCmd("hostname", true) | ||
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("/usr/local/bin/kubectl cordon %s ", nodeName), true); err != nil { | ||
return errors.Wrap(err, fmt.Sprintf("cordon the node: %s failed", nodeName)) | ||
} | ||
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf( | ||
"/usr/local/bin/kubectl drain %s --delete-emptydir-data --ignore-daemonsets --timeout=2m --force", nodeName), | ||
true); err != nil { | ||
return errors.Wrap(err, fmt.Sprintf("drain the node: %s failed", nodeName)) | ||
} | ||
// if _, err := runtime.GetRunner().SudoCmd("systemctl stop kubelet", false); err != nil { | ||
// return errors.Wrap(errors.WithStack(err), fmt.Sprintf("stop kubelet failed: %s", nodeName)) | ||
// } | ||
if err := UninstallContainerTasks(runtime, d.KubeAction); err != nil { | ||
return errors.Wrap(errors.WithStack(err), fmt.Sprintf("Uninstall ContainerTasks failed: %s", nodeName)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see these codes are duplicated with MigrateSelfNodeTocontainerd
, so I suggest modifying them as a new task.
Just an advice, maybe after that the MigrateSelfNodeToDocker
can become to:
func (d *MigrateSelfNodeToDocker) Execute(runtime connector.Runtime) error {
CordonTask
DrainTask
uninstallTask
MigrateTask
RestartTask
UnCordonTask
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, a good advice, I will optimize it,soon
pkg/container/module.go
Outdated
if p.KubeConf.Arg.Type == common.Docker && p.KubeConf.Arg.Role == common.Worker { | ||
p.Tasks = MigrateToDocker(p) | ||
} else if p.KubeConf.Arg.Type == common.Docker && p.KubeConf.Arg.Role == common.Master { | ||
p.Tasks = MigrateMToDocker(p) | ||
} else if p.KubeConf.Arg.Type == common.Conatinerd && p.KubeConf.Arg.Role == common.Worker { | ||
p.Tasks = MigrateToContainerd(p) | ||
} else if p.KubeConf.Arg.Type == common.Conatinerd && p.KubeConf.Arg.Role == common.Master { | ||
p.Tasks = MigrateMToContainerd(p) | ||
} else { | ||
logger.Log.Fatalf("Unsupported container runtime: %s", strings.TrimSpace(p.KubeConf.Arg.Type)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened if the flag role
support this --role all
? Add a new module?
Maybe we just need to add a new prepare
to determine if the node should be skipped.
var action task.Action
switch type {
case docker:
action = new(MigrateSelfNodeToDocker)
case contained:
action = new(MigrateSelfNodeToContainerd)
}
migrate = &task.RemoteTask{
Name: "MigrateToDocker",
Desc: "Migrate To Docker",
Hosts: p.Runtime.GetHostsByRole(common.k8s),
Prepare: new(RolePrepare),
Action: action,
Parallel: false,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,I will optimize it,soon
ea40b6f
to
61a0ce0
Compare
pkg/container/containerd.go
Outdated
} | ||
|
||
} | ||
if _, err := runtime.GetRunner().SudoCmd(fmt.Sprintf("/usr/local/bin/kubectl uncordon %s", nodeName), true); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this task need to execute twice uncordon
commands?
cmd/ctl/cri/migrate_cri.go
Outdated
cmd.Flags().StringVarP(&o.Role, "role", "", "worker", "Role to migrate") | ||
cmd.Flags().StringVarP(&o.Type, "type", "", "docker", "Type to migrate") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is recommended not to set the default value. And the description needs more detailed, for example, which roles can be specified, and which types can be specified.
cmd/ctl/cri/migrate_cri.go
Outdated
if o.Role == "" { | ||
return errors.New("node Role can not be empty") | ||
} | ||
if o.Type == "" { | ||
return errors.New("cri Type can not be empty") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check the user input value if it is valid, rather than only check if it is empty.
61a0ce0
to
72a6ad6
Compare
cmd/ctl/cri/migrate_cri.go
Outdated
|
||
func (o *MigrateCriOptions) Validate() error { | ||
if o.Role == "" || (o.Role != common.Worker && o.Role != common.Master && o.Role != "all") { | ||
return errors.New("node Role should be valid ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if o.Role == "" {
return errors.New("The role can not be empty")
}
if o.Role != common.Worker && o.Role != common.Master && o.Role != "all" {
return errors.Errorf("role %s is invalid", o.Role)
}
72a6ad6
to
a856427
Compare
Signed-off-by: zhoutian <zhoutian@yunify.com>
a856427
to
0ea2a0d
Compare
/lgtm |
LGTM label has been added. Git tree hash: 9df097d779cd142634bff844c6570feedc507a50
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: 24sama, zt1046656665 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
migrate
What this PR does / why we need it:
we add migrate_cri
Which issue(s) this PR fixes:
Fixes #
Special notes for reviewers:
Does this PR introduced a user-facing change?
Additional documentation, usage docs, etc.: